# -*- coding: utf-8 -*-
# flake8: noqa
from qiniu import Auth, put_file, etag
import qiniu.config

# 需要填写你的 Access Key 和 Secret Key
access_key = 'l9Dc1F5xXpMuZeag90NQ-GvBIAAr_6qFl1czB9W8'
secret_key = 'txP-CjINoUvpWtOutwUNg27CUjSKTHjuK1uI5NCn'
# 构建鉴权对象
q = Auth(access_key, secret_key)
# 要上传的空间
bucket_name = 'bokee'
# url前缀
url_prefix = "http://qikvfrole.hn-bkt.clouddn.com/"


def save_img(localfile, key):
    # 生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    ret, info = put_file(token, key, localfile)
    print(info)
    assert ret['key'] == key
    assert ret['hash'] == etag(localfile)
    return url_prefix + key


if __name__ == "__main__":
    save_img()
